<?php
include("../conn.php");

// 需传参数
$shopid = $_REQUEST[shopid];
$total=$_REQUEST[total];
$userid = $_REQUEST[userid];
// 需传参数 end

//商家优惠券
$today = date("Y-m-d");
$query=mysql_query("select * from coupon join mycoupon on coupon.couponid=mycoupon.couponid  where coupon.shopid=".$shopid."  and  mycoupon.userid='".$userid."' and mycoupon.is_use=0  and coupon.state=1  and  mycoupon.is_delete=0  and startdate<='".$today."'  and  enddate>='".$today."'");

$arr=array();
$i=0;
while ($result=mysql_fetch_assoc($query)) {
	if ($total>=$result[top_price]) {
		$arr[$i]=$result;
		$i++;
	}
}

//平台优惠券
$query = mysql_query("select * from coupon join mycoupon on coupon.couponid=mycoupon.couponid  where  mycoupon.userid='".$userid."'  and  coupon.shopid=0 and  and mycoupon.is_use=0  and coupon.state=1   and  mycoupon.is_delete=0  and startdate<='".$today."'  and  enddate>='".$today."'");
$i=0;
while ($result=mysql_fetch_assoc($query)) {
	$sql2="select * from shop where shopid=".$shopid;
	$result2=mysql_query($sql2);
	$row2 = mysql_fetch_assoc($result2);
	$coupon_ids = explode(",",$row2[coupon_ids]);

	if (in_array($result[couponid], $coupon_ids) && $total>=$result[top_price]) {
		$arr[$i]=$result;
		$i++;
	}
}
echo json_encode(array('code' => 200,'msg' => "查询成功",'data' => $arr ));
?>